function fn() {
    return this.length + 1;
}
var length = 10;
var obj = {
    length: 5,
    test1: function () {
        return fn();
    },
};
obj.test2 = fn;
//字节经典题，下面代码输出是什么
console.log(obj.test1());
// obj.test1() => fn() => window.fn() => window.length + 1 => 10 + 1
console.log(fn() === obj.test2());
// fn() => window.fn() => window.length + 1 => 10 + 1
// obj.test2() => obj.fn() => obj.length + 1 => 5 + 1

//  --------------------------------------------------------
function fun(n, o) {
    console.log(o);
    return {
        fun: function (m) {
            return fun(m, n);
        },
    };
}

var a = fun(0);
a.fun(1);
a.fun(2);
a.fun(3);

var b = fun(0).fun(1).fun(2).fun(3);
var c = fun(0).fun(1);
c.fun(2);
c.fun(3);

// undefined 0 0 0
// undefined 0 1 2
// undefined 0 1 1

// ---------------------------
let a = 1;
const function1 = function () {
    console.log(a);
    a = 2;
};
a = 3;
const function2 = function () {
    console.log(a);
};
function1();
function2();
